<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<%@include file="/res/include/umeditor.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/mall/subject.js"></script>
  </head>
  <body>  
<div class="form_item topic_add">
   <form id="data-form">
   	<c:if test="${!empty mallSubjectVo}">
    	<input type="hidden" name="id" value="${mallSubjectVo.id }"/>
    </c:if>
    <dl>
        <dt>名称：</dt>
        <dd><input type="text" name="title" value="${mallSubjectVo.title }" class="txt grid-25 easyui-validatebox" data-options="required:true" maxlength="32"/></dd>
    </dl>
    <dl>
   		<dt>排序：</dt>
       	<dd><input type="text" class="txt grid-15 easyui-numberbox" precision="0" name="oidx" data-options="required:true" value="${mallSubjectVo.oidx }"/></dd>
    </dl>
    <dl>
        <dt>备注：</dt>
        <dd><input type="text" name="remark" value="${mallSubjectVo.remark }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
    <dl>
    	<dt>广告：</dt>
        <dd>
        	<ul class="product_imglist logo_img">
	        	<c:choose>
	        	<c:when test="${!empty mallSubjectVo && !empty mallSubjectVo.img}">
		        	<li>
		     			<a href="javascript:;" class="item" id="logoImg" onclick="admin.subject.addImg('logoImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSubjectVo.img }" alt="" /></p></a>
		     			<em onclick="delLogoImg(this)"></em>
		     		</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="logoImg" onclick="admin.subject.addImg('logoImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>	
         	</ul>
        </dd>
    </dl>
    <dl>
        <dt>状态：</dt>
        <dd>
        	<select name="status">
				<option value="1"
					<c:if test="${mallSubjectVo != null && mallSubjectVo.status==1}"> selected="selected"</c:if>
				>有效</option>
				<option value="2"
					<c:if test="${mallSubjectVo != null && mallSubjectVo.status==2}"> selected="selected"</c:if>
				>失效</option>
			</select>
        </dd>
    </dl>
    </form>
    <p class="page_btn"><input type="button" id="doSave" value="保存" class="btn_blue" onclick="doSave();"/></p>
</div>
<script type="text/javascript">

var isSave = false;
//提交保存
function doSave(){
	var logoImg = "";
	var logoImglist = $(".logo_img img");
	if (logoImglist && logoImglist.length > 0) {
		logoImglist.each(function(){
		    if (logoImg == "") {
		    	logoImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	logoImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var url = contextPath+'/mall/subject/add';
	<c:if test="${!empty mallSubjectVo}">
		url = contextPath+'/mall/subject/update';
	</c:if>
	if(!$('#data-form').form('validate')) return;
	if (isSave) {
		return;
	}
	isSave = true;
	var data = $('#data-form').form('jsonObject');
	data.img = logoImg;
	//console.info("------------:"+JSON.stringify(data));
	$.post(url,data,function(result) {
		if(result.code==1) {
			top.showInfo('保存成功');
		} else {
			isSave = false;
			top.showInfo('保存失败:'+result.msg);
		}
	},'json');
}

function delLogoImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="logoImg" onclick="admin.supplier.addImg(\'logoImg\')">添加图片</a>');
}
</script>
  </body>
</html>
